<!DOCTYPE html>
<html>

<head lang="en">
    <meta charset="UTF-8">
    <meta name="format-detection" content="telephone=no" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <title>草稿列表</title>
    <link href="../css/font.css" type="text/css" rel="stylesheet">
    <link href="../css/style.css" type="text/css" rel="stylesheet">
    <!--block[hdcss]-->

    <!--block[hdcss]end-->
</head>

<body>
    <!--block[content]-->
    <section class="wrap">
        <div class="page">
            <!--<header class="hd">头部 </header>-->
            <ul class="m-list">

            </ul>
            <div class="u-btn-area">
                <a class="u-btn u-btn-error" style="display:none" id="u-btn-error" href="javascript:void(0)">
                删&nbsp;&nbsp;除
            </a>
            </div>
        </div>
    </section>
    <footer class="ft">底部 </footer>
    <!--block[content]end-->
    <script type="text/tmpl" id="jTmpl_user_list">
        {{#data}}
        <li order-id="{{order_id}}">
            <div class="thumb">
                <span class="checkbox fa fa-circle-o"></span>
            </div>

            <div class="cont">
                <a href="http://lres.gzhc365.com/gxyj/html/bianjicaogao.html?order_id={{order_id}}" class="link">
                    <div>{{subject}}</div>
                    <div><span class="date">{{start_at}}</span></div>
                </a>
            </div>
            <!-- <div class="flag">
            <span class="fa fa-angle-right"></span>
        </div> -->
             
        </li>
        {{/data}}
    </script>
    <script src="../js/lib/zepto.min.js" type="text/javascript"></script>
    <script src="../js/plugin/juicer-min.js" type="text/javascript"></script>
    <script src="../js/lib/mustache.js" type="text/javascript"></script>
    <script type="text/javascript">
        window.alert = function (name) {
            var iframe = document.createElement("IFRAME");
            iframe.style.display = "none";
            iframe.setAttribute("src", 'data:text/plain,');
            document.documentElement.appendChild(iframe);
            window.frames[0].window.alert(name);
            iframe.parentNode.removeChild(iframe);
        };

        var getDate = function (url, callback) {
            var type = type || 'get';
            $.ajax({
                url: url,// 跳转到 action
                type: 'get',
                dataType: 'jsonp',
                success: function (data) {
                    callback && callback(data);
                }
            });
        };

        let tpl = $('#jTmpl_user_list').html();

        const baseUrl = 'http://lres.gzhc365.com/gxyj/api/';
        let url = baseUrl + 'order/list?publish_status=0&callback=';

        function movieType(type) {
            var t = '';
            var s = '';
            switch (type) {
                case 0:
                    t = 'p-status-fail';
                    s = '未通过';
                    break;
                case 1:
                    t = 'p-status-ing';
                    s = '通过';
                    break;
                case 2:
                    t = 'p-status-doing';
                    s = '待审核';
                    break;
                default:
                    t = '';
            }

            return { style: t, txt: s };
        }

        getDate(url, function (json) {
            console.log(json.data)

            //p-status-fail 未通过
            //p-status-ing  通过
            //p-status-doing  待审核


            if (json && json.code == 200) {
                let data = json.data;
                $.each(data.data, function (i) {
                    console.log(data.data[i].check_status)
                    data.data[i].status = movieType(data.data[i].check_status).style
                    data.data[i].txt = movieType(data.data[i].check_status).txt
                });


                if (data.data.length) {
                    $('#u-btn-error').show();
                } else {
                    $('.page').append('<p style="text-align:center">您好，数据为空</p>')
                }

                let element = Mustache.render(tpl, data);
                $('.m-list').html(element);
            } else if (json.code == 1003) {
                let l = window.location.href;
                window.location = 'http://lres.gzhc365.com/gxyj/api/auth/wx_authorize?return_url=' + l
            }
        });

        $('.m-list').on('click', '.checkbox', function () {
            if ($(this).hasClass('fa-circle-o')) {
                $(this).removeClass('fa-circle-o')
                $(this).addClass('fa-check-circle-o')
            } else {
                $(this).removeClass('fa-check-circle-o ')
                $(this).addClass('fa-circle-o')
            }
        });

        $('#u-btn-error').on('click', function () {

            if ($('.checkbox').hasClass('fa-check-circle-o')) {
                $('.fa-check-circle-o').parent().parent().remove()
            } else {
                alert('请选择删除的对象');
            }

            let arr_id = [];
            

            $('.m-list li').each(function (index) {
                arr_id.push($(this).attr('order-id'));
            });

            let data = {
                order_id: arr_id
            }

            $.ajax({
                url: 'http://lres.gzhc365.com/gxyj/api/order/delete',// 跳转到 action
                type: 'post',
                data: data,
                xhrFields: {
                    withCredentials: true
                },
                success: function (data) {
                    if (data && data.code == 200) {
                        if($('.m-list').size() == 0) {
                            $('.u-btn-area').hide();
                        }
                    } else if (data.code == 1003) {
                        let l = window.location.href;
                        window.location = 'http://lres.gzhc365.com/gxyj/api/auth/wx_authorize?return_url=' + l
                    }
                }
            });


        })

    </script>
    <!--block[endscript]end-->
</body>

</html>